package pong.business.items;

import java.util.Calendar;
import java.util.Random;


public class Ball extends AbstractElement {
	
	private static final int NB_REFRESH_FOR_SPEED_INCREMENT = 10000;
	
	private static final int INITIAL_SPEED = 100;
	
	private static final float INITIAL_X = (float) 0.5;
	
	private static final float INITIAL_Y = (float) 0.5;
	
	private static final float INITIAL_DIRECTION = (float) 0.25;
	
	private int speed = INITIAL_SPEED;
	
	private float x = INITIAL_X;
	
	private float y = INITIAL_Y;
	
	private float direction = INITIAL_DIRECTION;
	
	public void run() {

		int nbRefresh = 0;
		
		// Sets the initial direction randomized.
		direction = direction - new Random().nextInt(2);
		
		while(true){
	
			if(!paused){
				
				if(nbRefresh % NB_REFRESH_FOR_SPEED_INCREMENT <= nbRefresh) {
					speed--;
				}
				
				// Compute ball position and notify UI.
			}
			
			try {
				Thread.sleep(speed);
			} catch (InterruptedException exception) {
				// Does nothing.
			}
			
			nbRefresh++;
		}
	}
	
	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public float getDirection() {
		return direction;
	}

	public void setDirection(float direction) {
		this.direction = direction;
	}
}
